#if ( !defined(PREP_H) && defined(__cplusplus) )
#define PREP_H

#include <stdint.h>
#include <wx/defs.h>
#define CB_LIBRARY_ENVVAR _T("LD_LIBRARY_PATH")

template <bool cond, class true_t, class false_t> struct TernaryCondTypedef {
  typedef true_t eval;
};

template <class true_t, class false_t> struct TernaryCondTypedef<false, true_t, false_t> {
  typedef false_t eval;
};

template <typename T> unsigned int array_size( const T& array ) {
  enum {result = sizeof( array ) / sizeof( array[0] )};
  return result;
}
template<typename T>inline void Delete( T*& p ) {
  delete p;
  p = nullptr;
}
template<typename T>inline void DeleteArray( T*& p ) {delete[] p; p = nullptr;}

namespace compatibility {
  const int wxHideReadonly = 0;
}

class ID {
    wxIntPtr value;
    ID( wxIntPtr in ) : value( in ) {};
    template<typename> friend ID GetID();
    friend ID ConstructID( wxIntPtr );
  public:
    ID() : value( ( wxIntPtr ) - 1 ) {};
    operator wxIntPtr() const { return value; };
    operator void*() const { return reinterpret_cast<void*>( static_cast<uintptr_t>( value ) ); };
    bool Valid() const { return value != ( ( wxIntPtr ) - 1 ); };
    bool operator!() const { return !Valid(); };
    friend bool operator==( ID a, ID b ) { return a.value == b.value; };
    friend bool operator==( ID a, int b ) { return a.value == ( wxIntPtr ) b; };
    friend bool operator!=( ID a, ID b ) { return a.value != b.value; };
    friend bool operator!=( ID a, int b ) { return a.value != ( wxIntPtr ) b; };
};


template<typename whatever> inline ID GetID() {
  static wxIntPtr id = ( wxIntPtr ) - 1;
  return ID( ++id );
}

inline ID GetID() { return GetID<void>(); }
inline ID ConstructID( wxIntPtr i ) { return ID( i ); }

#include <ciso646>
#include <memory>

namespace cb {
  using std::shared_ptr;
  using std::static_pointer_cast;
  using std::weak_ptr;
}

#endif
